﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

namespace PropertyManagement.zhuhu
{
    public partial class editZhuHu2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sid = Request.QueryString["id"];
            if (!IsPostBack && sid != null && !sid.Equals(""))
            {
                BindTextBox(sid);
            }
        }

        private void BindTextBox(string sid)
        {
            int id;
            id = Int16.Parse(sid);
            string strsql = "select * from szhuhu where id=" + id;

            mydata myda = new mydata();
            MySqlDataReader dread = myda.getDataReader(strsql);

            if (dread.HasRows)
            {
                dread.Read();
                sid = dread["id"].ToString();
                txtId.Text = sid;

                txtsname.Text = dread["sname"].ToString();
                DropDownList1.SelectedValue = dread["lddy"].ToString();
                txtfanghao.Text = dread["fanghao"].ToString();
                DropDownList2.SelectedValue = dread["fangxing"].ToString();
                txtjzmj.Text = dread["jzmj"].ToString();
                txtqrdate.Text = dread["qrdate"].ToString();
                txttel.Text = dread["tel"].ToString();
            }

            dread.Close();
            myda.closeAll();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sid, sname, lddy, fanghao, fangxing, jzmj, qrdate, tel;

            sid = txtId.Text;
            sname = txtsname.Text;
            lddy = DropDownList1.SelectedValue;
            fanghao = txtfanghao.Text;
            fangxing = DropDownList2.SelectedValue;
            jzmj = txtjzmj.Text;
            qrdate = txtqrdate.Text;
            tel = txttel.Text;

            int id = Int16.Parse(sid);

            string strsql = "update szhuhu set " +
                "sname='" + sname + "'," +
                "lddy='" + lddy + "'," +
                "fanghao='" + fanghao + "'," +
                "fangxing='" + fangxing + "'," +
                "jzmj='" + jzmj + "'," +
                "qrdate='" + qrdate + "'," +
                "tel='" + tel + "'" +
                "where id=" + id;

            int n;
            mydata myda = new mydata();
            n = myda.execSql(strsql);
            if (n > 0)
            {
                Response.Write("<script language=javascript> alert('更新数据成功') </script>");
            }
            else
            {
                Response.Write("<script language=javascript> alert('更新数据失败') </script>");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("editZhuHu.aspx");
        }
    }
}